package com.ruoyi.question.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.question.domain.DtQuestionType;
import com.ruoyi.question.service.IDtQuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 类型（如单选，多选）Controller
 *
 * @author llc
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/question/type")
public class DtQuestionTypeController extends BaseController {
    @Autowired
    private IDtQuestionTypeService dtQuestionTypeService;

    /**
     * 查询类型（如单选，多选）列表
     */
    @PreAuthorize("@ss.hasPermi('question:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtQuestionType dtQuestionType) {
        startPage();
        List<DtQuestionType> list = dtQuestionTypeService.selectDtQuestionTypeList(dtQuestionType);
        return getDataTable(list);
    }

    /**
     * 导出类型（如单选，多选）列表
     */
    @PreAuthorize("@ss.hasPermi('question:type:export')")
    @Log(title = "类型（如单选，多选）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtQuestionType dtQuestionType) {
        List<DtQuestionType> list = dtQuestionTypeService.selectDtQuestionTypeList(dtQuestionType);
        ExcelUtil<DtQuestionType> util = new ExcelUtil<DtQuestionType>(DtQuestionType.class);
        util.exportExcel(response, list, "类型（如单选，多选）数据");
    }

    /**
     * 获取类型（如单选，多选）详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dtQuestionTypeService.selectDtQuestionTypeById(id));
    }

    /**
     * 新增类型（如单选，多选）
     */
    @PreAuthorize("@ss.hasPermi('question:type:add')")
    @Log(title = "类型（如单选，多选）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtQuestionType dtQuestionType) {
        return toAjax(dtQuestionTypeService.insertDtQuestionType(dtQuestionType));
    }

    /**
     * 修改类型（如单选，多选）
     */
    @PreAuthorize("@ss.hasPermi('question:type:edit')")
    @Log(title = "类型（如单选，多选）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtQuestionType dtQuestionType) {
        return toAjax(dtQuestionTypeService.updateDtQuestionType(dtQuestionType));
    }

    /**
     * 删除类型（如单选，多选）
     */
    @PreAuthorize("@ss.hasPermi('question:type:remove')")
    @Log(title = "类型（如单选，多选）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dtQuestionTypeService.deleteDtQuestionTypeByIds(ids));
    }
}
